package com.google.code.sms.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;

import com.google.code.sms.domain.Player;
import com.google.code.sms.domain.User;
import com.google.code.sms.service.PlayerService;
import com.google.code.sms.service.SecurityService;
import com.google.code.sms.service.SettingsService;

/**
 * Controller for the playlist frame.
 *
 * @author Sindre Mehus
 */
public class PlayQueueController extends ParameterizableViewController {

    private PlayerService playerService;
    private SecurityService securityService;
    private SettingsService settingsService;

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

        User user = securityService.getCurrentUser(request);
        Player player = playerService.getPlayer(request, response);

        Map<String, Object> map = new HashMap<>();
        map.put("user", user);
        map.put("player", player);
        map.put("players", playerService.getPlayersForUserAndClientId(user.getUsername(), null));
        ModelAndView result = super.handleRequestInternal(request, response);
        result.addObject("model", map);
        return result;
    }

    public void setPlayerService(PlayerService playerService) {
        this.playerService = playerService;
    }

    public void setSecurityService(SecurityService securityService) {
        this.securityService = securityService;
    }

    public void setSettingsService(SettingsService settingsService) {
        this.settingsService = settingsService;
    }
}